﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace ModelValidation.LongitudinalModel
{
	public partial class SettingForm : System.Windows.Forms.Form
	{
		public SettingForm()
		{
			this.InitializeComponent();
			this.InitializeTooltips();
		}

		public static CheckingTypeStates GetCheckingTypeStates()
		{
			CheckingTypeStates checkingTypeStates = new CheckingTypeStates();
			bool flag = true;
			string path = Path.GetTempPath() + "LongitudinalModelCheckingSettingForm.dat";
			if (File.Exists(path))
			{
				FileStream fileStream = new FileStream(path, FileMode.Open);
				StreamReader streamReader = new StreamReader(fileStream);
				streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
				int x = Convert.ToInt32(streamReader.ReadLine());
				int y = Convert.ToInt32(streamReader.ReadLine());
				new System.Drawing.Point(x, y);
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.FloorAndArchWall = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.StructWallAndFloor = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.BeamAndFloor = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.BeamAndStructColumn = CheckingOrder.CO_SecondToFirst;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.BeamAndArchColumn = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.StructColumnAndFloor = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.StructColumnAndArchWall = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.StructColumnAndStructWall = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.BeamAndArchWall = CheckingOrder.CO_FirstToSecond;
				}
				if (Convert.ToBoolean(streamReader.ReadLine()))
				{
					checkingTypeStates.BeamAndStructWall = CheckingOrder.CO_FirstToSecond;
				}
				try
				{
					flag = Convert.ToBoolean(streamReader.ReadLine());
					if (flag)
					{
						checkingTypeStates.StructWallAndArchWall = CheckingOrder.CO_FirstToSecond;
					}
					streamReader.Close();
					fileStream.Close();
					return checkingTypeStates;
				}
				catch (Exception)
				{
					if (flag)
					{
						checkingTypeStates.StructWallAndArchWall = CheckingOrder.CO_FirstToSecond;
					}
					streamReader.Close();
					fileStream.Close();
					return checkingTypeStates;
				}
				return checkingTypeStates;
			}
			return checkingTypeStates;
		}

		private void InitializeTooltips()
		{
			new ToolTip().SetToolTip(this.pbFloor_AWall, this.pbFloor_AWall.Tag.ToString());
			new ToolTip().SetToolTip(this.pbSWall_AWall, this.pbSWall_AWall.Tag.ToString());
			new ToolTip().SetToolTip(this.pbSWall_Floor, this.pbSWall_Floor.Tag.ToString());
			new ToolTip().SetToolTip(this.pbBeam_Floor, this.pbBeam_Floor.Tag.ToString());
			new ToolTip().SetToolTip(this.pbSColumn_Beam, this.pbSColumn_Beam.Tag.ToString());
			new ToolTip().SetToolTip(this.pbBeam_AColumn, this.pbBeam_AColumn.Tag.ToString());
			new ToolTip().SetToolTip(this.pbSColumn_Floor, this.pbSColumn_Floor.Tag.ToString());
			new ToolTip().SetToolTip(this.pbSColumn_AWall, this.pbSColumn_AWall.Tag.ToString());
			new ToolTip().SetToolTip(this.pbSColumn_SWall, this.pbSColumn_SWall.Tag.ToString());
			new ToolTip().SetToolTip(this.pbBeam_AWall, this.pbBeam_AWall.Tag.ToString());
			new ToolTip().SetToolTip(this.pbBeam_SWall, this.pbBeam_SWall.Tag.ToString());
		}

		private void SettingForm_Load(object sender, EventArgs e)
		{
			base.Icon = Resource.YArchitechIcon;
			this.ReadData();
		}

		private void SettingForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult != DialogResult.OK)
			{
				return;
			}
			if (!this.chkbBeam_SWall.Checked && !this.chkbBeam_AWall.Checked && !this.chkbFloor_AWall.Checked && !this.chkbSColumn_SWall.Checked && !this.chkbSWall_AWall.Checked && !this.chkbSWall_Floor.Checked && !this.chkbBeam_Floor.Checked && !this.chkbBeam_AColumn.Checked && !this.chkbSColumn_Beam.Checked && !this.chkbSColumn_Floor.Checked && !this.chkbSColumn_AWall.Checked)
			{
				e.Cancel = true;
				MessageBox.Show("至少选择一项规则", "盈建科提示");
				return;
			}
			this.SaveData();
		}

		private void ReadData()
		{
			string path = Path.GetTempPath() + "LongitudinalModelCheckingSettingForm.dat";
			if (!File.Exists(path))
			{
				base.StartPosition = FormStartPosition.CenterScreen;
				this.chkbFloor_AWall.Checked = true;
				this.chkbSWall_AWall.Checked = true;
				this.chkbSWall_Floor.Checked = true;
				this.chkbBeam_Floor.Checked = true;
				this.chkbSColumn_Beam.Checked = true;
				this.chkbBeam_AColumn.Checked = true;
				this.chkbSColumn_Floor.Checked = true;
				this.chkbSColumn_AWall.Checked = true;
				this.chkbSColumn_SWall.Checked = true;
				this.chkbBeam_AWall.Checked = true;
				this.chkbBeam_SWall.Checked = true;
				return;
			}
			base.StartPosition = FormStartPosition.Manual;
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			int x = Convert.ToInt32(streamReader.ReadLine());
			int y = Convert.ToInt32(streamReader.ReadLine());
			base.Location = new System.Drawing.Point(x, y);
			this.chkbFloor_AWall.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbSWall_Floor.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbBeam_Floor.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbSColumn_Beam.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbBeam_AColumn.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbSColumn_Floor.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbSColumn_AWall.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbSColumn_SWall.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbBeam_AWall.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkbBeam_SWall.Checked = Convert.ToBoolean(streamReader.ReadLine());
			try
			{
				this.chkbSWall_AWall.Checked = Convert.ToBoolean(streamReader.ReadLine());
				streamReader.Close();
				fileStream.Close();
			}
			catch (Exception)
			{
				streamReader.Close();
				fileStream.Close();
			}
		}

		private void SaveData()
		{
			FileStream fileStream = new FileStream(Path.GetTempPath() + "LongitudinalModelCheckingSettingForm.dat", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(base.Location.X);
			streamWriter.WriteLine(base.Location.Y);
			streamWriter.WriteLine(this.chkbFloor_AWall.Checked);
			streamWriter.WriteLine(this.chkbSWall_Floor.Checked);
			streamWriter.WriteLine(this.chkbBeam_Floor.Checked);
			streamWriter.WriteLine(this.chkbSColumn_Beam.Checked);
			streamWriter.WriteLine(this.chkbBeam_AColumn.Checked);
			streamWriter.WriteLine(this.chkbSColumn_Floor.Checked);
			streamWriter.WriteLine(this.chkbSColumn_AWall.Checked);
			streamWriter.WriteLine(this.chkbSColumn_SWall.Checked);
			streamWriter.WriteLine(this.chkbBeam_AWall.Checked);
			streamWriter.WriteLine(this.chkbBeam_SWall.Checked);
			streamWriter.WriteLine(this.chkbSWall_AWall.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private void btnSelectAll_Click(object sender, EventArgs e)
		{
			this.chkbFloor_AWall.Checked = true;
			this.chkbSWall_AWall.Checked = true;
			this.chkbSWall_Floor.Checked = true;
			this.chkbBeam_Floor.Checked = true;
			this.chkbSColumn_Beam.Checked = true;
			this.chkbBeam_AColumn.Checked = true;
			this.chkbSColumn_Floor.Checked = true;
			this.chkbSColumn_AWall.Checked = true;
			this.chkbSColumn_SWall.Checked = true;
			this.chkbBeam_AWall.Checked = true;
			this.chkbBeam_SWall.Checked = true;
		}

		private void btnSelectNone_Click(object sender, EventArgs e)
		{
			this.chkbFloor_AWall.Checked = false;
			this.chkbSWall_AWall.Checked = false;
			this.chkbSWall_Floor.Checked = false;
			this.chkbBeam_Floor.Checked = false;
			this.chkbSColumn_Beam.Checked = false;
			this.chkbBeam_AColumn.Checked = false;
			this.chkbSColumn_Floor.Checked = false;
			this.chkbSColumn_AWall.Checked = false;
			this.chkbSColumn_SWall.Checked = false;
			this.chkbBeam_AWall.Checked = false;
			this.chkbBeam_SWall.Checked = false;
		}
	}
}
